// state/StateMachine.h

#ifndef _STATE_StateMachine_H_
#define _STATE_StateMachine_H_

#ifndef _CORE_std_H_
#include <core/std.h>
#endif

#ifndef _STATE_Defines_H_
#include "StateDefines.h"
#endif

struct IRenderingEngine;

namespace STATE
{

class State;

class StateMachine
{
public:

	StateMachine();

	void		SetupStateMachine( State ** ppStates, int NumStates, int iInitialState=STATE_ID_INVALID);

	// Accessors
	bool		IsActive() const {
		return m_CurrentState >= 0;
	}

	// APIs
	void		Update( CORE::Time & TimeDelta );
	void		Render( IRenderingEngine * pRenderer );

	void		SetNextState( StateId NextState );

private:

	CORE::Array<State *>	m_pStates;

	State *					m_pCurrentState;

	StateId					m_CurrentState;
	StateId					m_NextState;
};

inline StateMachine::StateMachine()
	: m_pCurrentState(0)
	, m_CurrentState( STATE_ID_NONE )
	, m_NextState( STATE_ID_INVALID )
{
}

inline void StateMachine::SetNextState( StateId NextState )
{
	m_NextState = NextState;
}

}; // namespace STATE

#endif